<template>
  <div>
    <button @click="isShow = true">打开弹窗</button>
    <teleport to="body">
      <div class="mask" v-if="isShow">
        <div class="dialog">
          <h4>弹窗标题</h4>
          <hr />
          <p>弹窗内容</p>
          <p>弹窗内容</p>
          <p>弹窗内容</p>
          <button @click="isShow = false">关闭弹窗</button>
        </div>
      </div>
    </teleport>
  </div>
</template>

<script>
import { ref } from "vue";
export default {
  name: "dialog",
  setup() {
    let isShow = ref(false);
    return { isShow };
  },
};
</script>

<style scoped>
.mask {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: rgba(0, 0, 0, 0.4);
}
.dialog {
  text-align: center;
  position: absolute;
  /* 弹窗垂直居中 */
  /* top: calc(50% - 150px);
  left: calc(50% - 150px); */
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 300px;
  height: 300px;
  padding: 10px;
  border-radius: 7px;
  background-color: greenyellow;
}
</style>
